package com.yinhe.music.common.utils;

import android.content.Context;
import android.media.MediaScannerConnection;
import android.net.Uri;

import java.io.File;

/**
 * @author 何晓华
 * 扫描本地媒体库
 */
public class ScanMusicUtil implements MediaScannerConnection.MediaScannerConnectionClient {
    public interface ScanListener{
         void onScanFinish();
    }


    private MediaScannerConnection mMs;
    private File mFile;
    private ScanListener listener;

    public ScanMusicUtil(Context context, File f, ScanListener l) {
        listener = l;
        mFile = f;
        mMs = new MediaScannerConnection(context, this);
        mMs.connect();
    }


    @Override
    public void onMediaScannerConnected() {
        mMs.scanFile(mFile.getAbsolutePath(), null);
    }

    @Override
    public void onScanCompleted(String path, Uri uri) {
        mMs.disconnect();
        listener.onScanFinish();
    }
}
